﻿using System;
using System.Runtime.InteropServices;
using SlimDX;
using SlimDX.Direct3D9;

namespace BasicFramework.Rendering.Primitives.Vertizes
{

    public struct ColorVertex : IVertexBase, IEquatable<ColorVertex>
    {

        #region Fields

        #endregion

      #region Properties

        public Vector3 Position
        {
            get;
            set;
        }

        public int Color { get; set; }


        public int GetSize
        {
            get { return Marshal.SizeOf(typeof(ColorVertex)); }
        }

        public VertexElement[] GetVertexElements
        {
            get
            {
                return new[]
                           {
                               new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default,
                                                 DeclarationUsage.Position, 0),
                               new VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default,
                                                 DeclarationUsage.Color, 0),
                               VertexElement.VertexDeclarationEnd
                           };
            }

        }
        #endregion


        #region Constructors

        public ColorVertex(Vector3 position, int color)
            : this()
        {
            Position = position;
            Color = color;
        }

        #endregion


        #region Events

        #endregion

        #region Methods

        public static bool operator ==(ColorVertex left, ColorVertex right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(ColorVertex left, ColorVertex right)
        {
            return !(left == right);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        #endregion

        #region IEquatable<ColorVertex> Members

        public override bool Equals(object other)
        {
            if (other == null)
                return false;

            return GetType() == other.GetType() && this.Equals(other);
        }

        public bool Equals(ColorVertex other)
        {
            return (Position == other.Position && Color == other.Color);
        }
        #endregion

    }

}
